<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>员工管理</title>
	<script type="text/javascript">
		var menu_flag = 'user';
	</script>
</head>
<body>
	
	<div class="sitemap" id="sitemap">
		当前位置: 员工管理
	</div>
	
	<div class="mainoutside">
		<div class="secmainoutside">
			<div class="mainarea_shop">
				<div class="servicesearch pt18">
					<form action="" method="get">
						姓名：<input type="text" name="name" value="${param.name }"/>&nbsp;&nbsp;
						账号状态：<select name="activable">
							<option value="0">==所有==</option>
							<option value="1" <c:if test="${param.activable=='1' }"> selected="selected"</c:if>>激活</option>
							<option value="2" <c:if test="${param.activable=='2' }"> selected="selected"</c:if>>冻结</option>
						</select>&nbsp;&nbsp;
						<button type="submit" class="butsearch" id="btn-search">查询</button>
					</form>
				</div>
				<div class="operateShop">
					<ul>
						<li><a href="${ctx }/user/add">添加</a></li>
						<li><a id="cmd-delete">删除</a></li>
						<li><a type="button" class="lang" id="cmd-active">激活账号</a></li>
						<li><a type="button" class="lang" id="cmd-disable">冻结账号</a></li>
					</ul>
				</div>
			</div>
			
			<table class="mainlist">
				<thead>
					<tr>
						<td width="2%"><input type="checkbox" class="checkall"/></td>
						<td>
							账号
						</td>
						<td>
							密码
						</td>
						<td>
							电话
						</td>
						<td>
							邮箱
						</td>
						<td>
							录入时间
						</td>
						<td>
							可用状态
						</td>
					</tr>
				</thead>
				<tbody>
					<c:if test="${result.recordCount == 0}">
						<tr>
							<td colspan="7" align="center">
								没有符合要求的数据！
							</td>
						</tr>
					</c:if>
					<c:forEach var="user" items="${result.data}">
						<tr onMouseOver="chgTrColor(this)" onMouseOut="chgTrColor(this)">
							<td align="center"><c:if test="${user.name!='admin' }"><input type="checkbox" name="recordId" value="${user.id }"/></c:if></td>
							<td align="center">
								<a href="${user.id }"><c:if test="${not user.activable }"><font color='red'>${user.name }</font></c:if>
								<c:if test="${user.activable }">${user.name }</c:if></a>
							</td>
							<td align="center">
								*****
							</td>
							<td align="center">
								${user.mobile }
							</td>
							<td align="center">
								${user.email }
							</td>
							<td align="center">
								<fmt:formatDate value="${user.insertDate }" pattern="yyyy-MM-dd"/>
							</td>
							<td align="center">
								<c:if test="${user.activable }">激活</c:if><c:if test="${not user.activable }">冻结</c:if>
							</td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
			
			<div class="page">
				<div class="pageContent">
					<c:if test="${result.recordCount != 0}">
						<ccgk:pagination paginationVo="${result}" contextPath="${ctx}/user/list"/>
					</c:if>
				</div>
			</div>
			
		</div>
	</div>
	<script type="text/javascript">
		function checkId(){
			var item = $("[name=recordId]");
			var id = "";
			if (item.size() > 0) {
				item.each(function() {
							if ($(this).attr("checked") == true) {
								id += $(this).val();
								id += ",";
							}
						});
			}
			id = id.substr(0, id.lastIndexOf(","));
			if (id == "") {
				$.alert("请选择记录");
				return '';
			} else {
				return id;
			}
	
		}
	
		$("#cmd-delete").click(function() {
					var id = checkId();
					if (id != ''){
						$.alert("删除用户账号后将不能登录及其它一切操作，且不可恢复，确定删除吗？", function() {
							$.get("delete", {
								id : id
							}, function(data) {
								$.alert("删除成功！");
								window.location.reload();
							});
						}, true);
					}
				});

		$("#cmd-active").click(function() {
			var id = checkId();
			if (id != '') {
				$.alert("确定激活选中的账号吗？", function() {
					$.get("active", {
						id : id
					}, function(data) {
						$.alert("激活成功！");
						window.location.reload();
					});
				}, true);
			}
		});
		$("#cmd-disable").click(function() {
			var id = checkId();
			if (id != '') {
				$.alert("账号冻结后用户将不能登录系统，确定冻结选中的账号吗？", function() {
					$.get("disable", {
						id : id
					}, function(data) {
						$.alert("冻结成功！");
						window.location.reload();
					});
				}, true);
			}
		});
	</script>
</body>
</html>